namespace Microsoft.VisualStudio.EnterpriseTools.OperationDesigner
{
    using Microsoft.VisualStudio.EnterpriseTools.ArtifactModel.Clr;
    using System;
    using System.ComponentModel;
    using System.Drawing.Design;
    using System.Security.Permissions;
    using System.Windows.Forms.Design;

    public class SummaryEditor : UITypeEditor
    {
        private string f1Keyword;

        public SummaryEditor()
        {
        }

        public SummaryEditor(string f1Keyword)
        {
            this.f1Keyword = f1Keyword;
        }

        [SecurityPermission(SecurityAction.LinkDemand)]
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            ClrElement element = context.Instance as ClrElement;
            if (element == null)
            {
                ICustomTypeDescriptor descriptor = context.Instance as ICustomTypeDescriptor;
                if (descriptor != null)
                {
                    element = descriptor.GetPropertyOwner(context.PropertyDescriptor) as ClrElement;
                }
            }
            if (element != null)
            {
                IWindowsFormsEditorService service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                if (service != null)
                {
                    string docSummary = element.DocSummary;
                    SummaryForm dialog = new SummaryForm(provider, element, this.f1Keyword);
                    service.ShowDialog(dialog);
                }
            }
            return value;
        }

        [SecurityPermission(SecurityAction.LinkDemand)]
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }
    }
}

